/* 
	File: blog
	
	Este archivo administra todo el código JavaScript asociado al HTML blog.html

	Ver:
	<WebPage>
*/


function Blog()
{
	this.def_conf =
	{
		form:
		{
			data:
			{
				title:		"Blog",
				show_rows:	true,
				new_row:	true
				
			},

			class_names:
			{
				title:		"header",
				content:	"message_box",
				footer:		""
			},
		
			contents:
			{
				form:		function(title, content, footer)
				{
					var div = createElement({ type_node: "div", children: [ content, footer ] });

					return createBorderElement(title, div);
				}
			}
		},

		row:
		{
			data:
			{
				title:		"",
				edit: 		true,
				erase:		true,

				url:		"server/blog.php"
			},

			class_names:
			{
				title:		"header",
				content:	"main_content",
				footer:		""
			},

			contents:
			{
				mixture_out:	function(div_cells)
				{
					return createElement(	{ type_node: "div", children: 
												[	{ type_node: "h2", children: [ div_cells[2] ] }, 
													{ type_node: "p", children: [ div_cells[1], div_cells[4] ] },
													{ type_node: "p", children: [ div_cells[3] ] }
												]
											});		
				},

				mixture_in:		function(div_cells)
				{
					return createElement(	{ type_node: "div", children: 
												[	div_cells[2], div_cells[1], div_cells[3]	]
											});		
				}
			}
		},

		new_row:
		{
			data:
			{
				title:		"Nueva entrada"
			},

			class_names:
			{
				title:		"header",
				content:	"main_content",
				footer:		""
			},

			contents:
			{
				row:		function(title, content, footer)
				{
					return createBorderElement(title, createElement({ type_node: "div", children: [ content, footer ]}));
				},

				mixture_in:		function(div_cells)
				{
					return createElement(	{ type_node: "div", children: 
												[	div_cells[2], div_cells[1], div_cells[3]	]
											});		
				}
			}
		
		},
	
		fields:
		{
			output:
			{
				class_names:
				{
					div_cell:		"",
					div_title:		"label",
					div_value:		"input"
				},

				contents:
				{
					div_cell:		function(title, content)
					{
						return createElement({ type_node: "p", children: [ content ] });
					}
				}
			},
				
		},
			
			
		par:
		{
			input:
			{
				class_names:
				{
					div_cell:		"field selected_field",
					div_title:		"label",
					div_input:		"input",
					div_error:		"fr"
				}
			}
		},

		impar:
		{
			input:
			{
				class_names:
				{
					div_cell:		"field nonselected_field",
					div_title:		"label",
					div_input:		"input",
					div_error:		"fr"
				}
			}
		}
	};



	this.fields_conf  =
	[
		{ data: { name: "Id", auto_value: true } },
		{ data: { name: "Autor" } },
		{ data: { name: "Título" } },
		{ data: { name: "Texto" } },
		{ data: { name: "Fecha", auto_value: true } }
	];

	

}

Blog.prototype =
{
	onLoadPage:		function(web_page)
	{
		var json = {type_query: "SELECT"};

		new net.ContentLoader("server/blog.php", this.showResults, false, "params=" + JSONstring.make(json), this);
	},

	showResults:	function(req)
	{
		var json = eval('(' + req.responseText + ')');

		this.form = new Form(document.getElementById("blog_new"), json.fields_data, json.rows_data, this.def_conf, this.fields_conf);

		this.form.show("output");
	}
}

	
